package com.baiyu.scerp.customer.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.baiyu.common.annotation.Log;
import com.baiyu.common.enums.BusinessType;
import com.baiyu.scerp.customer.domain.ScCustomer;
import com.baiyu.scerp.customer.service.IScCustomerService;
import com.baiyu.common.core.controller.BaseController;
import com.baiyu.common.core.domain.AjaxResult;
import com.baiyu.common.utils.poi.ExcelUtil;
import com.baiyu.common.core.page.TableDataInfo;

/**
 * 客户信息Controller
 * 
 * @author wph
 * @date 2025-08-15
 */
@Controller
@RequestMapping("/scerp/customer")
public class ScCustomerController extends BaseController
{
    private String prefix = "scerp/customer";

    @Autowired
    private IScCustomerService scCustomerService;

    @RequiresPermissions("scerp:customer:view")
    @GetMapping()
    public String customer()
    {
        return prefix + "/customer";
    }

    /**
     * 查询客户信息列表
     */
    @RequiresPermissions("scerp:customer:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ScCustomer scCustomer)
    {
        startPage();
        List<ScCustomer> list = scCustomerService.selectScCustomerList(scCustomer);
        return getDataTable(list);
    }

    /**
     * 导出客户信息列表
     */
    @RequiresPermissions("scerp:customer:export")
    @Log(title = "客户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ScCustomer scCustomer)
    {
        List<ScCustomer> list = scCustomerService.selectScCustomerList(scCustomer);
        ExcelUtil<ScCustomer> util = new ExcelUtil<ScCustomer>(ScCustomer.class);
        return util.exportExcel(list, "客户信息数据");
    }

    /**
     * 新增客户信息
     */
    @RequiresPermissions("scerp:customer:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存客户信息
     */
    @RequiresPermissions("scerp:customer:add")
    @Log(title = "客户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ScCustomer scCustomer)
    {
        return toAjax(scCustomerService.insertScCustomer(scCustomer));
    }

    /**
     * 修改客户信息
     */
    @RequiresPermissions("scerp:customer:edit")
    @GetMapping("/edit/{customerId}")
    public String edit(@PathVariable("customerId") Long customerId, ModelMap mmap)
    {
        ScCustomer scCustomer = scCustomerService.selectScCustomerByCustomerId(customerId);
        mmap.put("scCustomer", scCustomer);
        return prefix + "/edit";
    }

    /**
     * 修改保存客户信息
     */
    @RequiresPermissions("scerp:customer:edit")
    @Log(title = "客户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ScCustomer scCustomer)
    {
        return toAjax(scCustomerService.updateScCustomer(scCustomer));
    }

    /**
     * 删除客户信息
     */
    @RequiresPermissions("scerp:customer:remove")
    @Log(title = "客户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(scCustomerService.deleteScCustomerByCustomerIds(ids));
    }
}
